package 分类.差分数组;

import java.util.ArrayList;
import java.util.Arrays;

public class 航班预订统计 {
    public int[] corpFlightBookings(int[][] bookings, int n) {
        int[] nums=new int[n];
        Arrays.fill(nums,0);
        int[] diff=new int[n];
        for (int[] booking : bookings) {
            int startIndex=booking[0]-1;
            int endIndex=booking[1]-1;
            int num=booking[2];
            diff[startIndex]+=num;
            if(endIndex+1<n){
                diff[endIndex+1]-=num;
            }

        }
        //进行数组的还原
        nums[0]=diff[0];
        for (int i=1;i<n;i++){
            nums[i]=nums[i-1]+diff[i];
        }
        return nums;
    }

}
